//package com.example.photography.Activity;
//
//import android.annotation.SuppressLint;
//import android.content.Intent;
//import android.graphics.Color;
//import android.os.Bundle;
//import android.os.Handler;
//import android.os.Message;
//import android.text.Editable;
//import android.text.TextUtils;
//import android.text.TextWatcher;
//import android.view.LayoutInflater;
//import android.view.View;
//import android.widget.Button;
//import android.widget.EditText;
//import android.widget.ExpandableListView;
//import android.widget.ImageView;
//import android.widget.LinearLayout;
//import android.widget.RelativeLayout;
//import android.widget.TextView;
//
//import androidx.core.widget.NestedScrollView;
//import androidx.recyclerview.widget.LinearLayoutManager;
//import androidx.recyclerview.widget.RecyclerView;
//
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONObject;
//import com.bumptech.glide.Glide;
//import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
//import com.bumptech.glide.request.RequestOptions;
//import com.example.photography.Model;
//import com.example.photography.R;
//import com.example.photography.adapter.Item_commentAdapter;
//import com.example.photography.adapter.Label_ProtoAdapter;
//import com.example.photography.adapter.PhotoAdapter;
//import com.example.photography.bean.Product_bean;
//import com.example.photography.bean.Product_contentBean;
//import com.example.photography.bean.UrlBean;
//import com.example.photography.common.AppNetConfig;
//import com.example.photography.common.BaseActivity;
//import com.example.photography.common.Constant;
//import com.example.photography.retrofit.ApiService;
//import com.example.photography.retrofit.net.exception.ApiException;
//import com.example.photography.retrofit.net.exception.ErrorConsumer;
//import com.example.photography.retrofit.net.response.ResponseTransformer;
//import com.example.photography.ui.CircleImageView;
//import com.example.photography.util.Util;
//import com.example.photography.view.CommentExpandableListView;
//import com.example.photography.view.LoadingDialog;
//import com.example.photography.view.MyListView;
//import com.google.android.material.bottomsheet.BottomSheetBehavior;
//import com.google.android.material.bottomsheet.BottomSheetDialog;
//
//import java.text.SimpleDateFormat;
//import java.util.Date;
//import java.util.List;
//
//import javax.inject.Inject;
//
//import butterknife.BindView;
//import butterknife.ButterKnife;
//import dagger.hilt.android.AndroidEntryPoint;
//import io.reactivex.functions.Consumer;
//
///**
// * 作品详情
// */
//@AndroidEntryPoint
//public class Product_Content extends BaseActivity {
//
//
//    @BindView(R.id.tl_iv_back)
//    ImageView tlIvBack;
//    @BindView(R.id.tl_tv_title)
//    TextView tlTvTitle;
//    @BindView(R.id.tl_iv_more)
//    ImageView tlIvMore;
//    @BindView(R.id.tl_iv_head)
//    ImageView tlIvHead;
//    @BindView(R.id.tl_tv_name)
//    TextView tlTvName;
//    @BindView(R.id.title_focus)
//    TextView titleFocus;
//    @BindView(R.id.tl_rl_item)
//    RelativeLayout tlRlItem;
//    @BindView(R.id.iv_head)
//    CircleImageView ivHead;
//    @BindView(R.id.tv_name)
//    TextView tvName;
//    @BindView(R.id.tv_date)
//    TextView tvDate;
//    @BindView(R.id.tv_focus)
//    TextView tvFocus;
//    @BindView(R.id.rl_item)
//    RelativeLayout rlItem;
//    @BindView(R.id.tv_presentation)
//    TextView tvPresentation;
//    @BindView(R.id.lv_product)
//    MyListView lvProduct;
//    @BindView(R.id.tv_group)
//    TextView tvGroup;
//    @BindView(R.id.rv_label)
//    RecyclerView rvLabel;
//    @BindView(R.id.lv_comment)
//    CommentExpandableListView lvComment;
//    @BindView(R.id.ns_view)
//    NestedScrollView nsView;
//    @BindView(R.id.send_comment)
//    TextView sendComment;
//    @BindView(R.id.iv_collect)
//    ImageView ivCollect;
//    @BindView(R.id.tv_collects)
//    TextView tvCollects;
//    @BindView(R.id.iv_like)
//    ImageView ivLike;
//    @BindView(R.id.tv_likes)
//    TextView tvLikes;
//    @BindView(R.id.ll_bottom)
//    LinearLayout llBottom;
//    private Product_bean productBean;
//    private Item_commentAdapter item_commentAdapter;
//    private BottomSheetDialog dialog;
//    private String product_id;
//    //注入动态代理实例对象
//    @Inject
//    ApiService apiService;
//    private TextView tv_more;
//
//    @Override
//    protected void initData() {
//        productBean = new Product_bean();
//        Intent intent = getIntent();
//        Bundle bundle = intent.getBundleExtra("data");
//        if (bundle != null && bundle.getString("product_id") != null) {
//            product_id = bundle.getString("product_id");
//            send_http();
//        }else {
//            Util.showToast(getApplicationContext(), "数据出错，请返回重试");
//        }
//        initListen();
//    }
//
//    @SuppressLint("CheckResult")
//    private void send_http() {
//        //开启等待动画
//        LoadingDialog.getInstance(this).show();
//        apiService.product_pro_id(product_id)
//                .compose(ResponseTransformer.obtain())
//                .subscribe(new Consumer<Product_bean>() {
//                    @Override
//                    public void accept(Product_bean product_bean) throws Exception {
//                        productBean = product_bean;
//                        mHandler.sendEmptyMessageDelayed(2,0);
//                    }
//                }, new ErrorConsumer() {
//                    @Override
//                    protected void error(ApiException e) {
//                        LoadingDialog.getInstance(Product_Content.this).dismiss();
//                        Message message = new Message();
//                        message.what = 1;
//                        message.obj = e.getErrorMsg();
//                        mHandler.sendMessage(message);
//
//                    }
//                });
//    }
//
//    private void initListen() {
//        //监听滑动
//        nsView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
//            @Override
//            public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
//                /**
//                 * 上滑隐藏底部框
//                 */
//                if (scrollY > oldScrollY) {
//                    llBottom.setVisibility(View.GONE);
//                } else {
//                    llBottom.setVisibility(View.VISIBLE);
//                }
//
//                /**
//                 * 显示两个不一样的title
//                 */
//                if (scrollY >= 120) {
//                    tlRlItem.setVisibility(View.VISIBLE);
//                    tlIvMore.setVisibility(View.GONE);
//                    tlTvTitle.setVisibility(View.GONE);
//                } else {
//                    tlRlItem.setVisibility(View.GONE);
//                    tlIvMore.setVisibility(View.VISIBLE);
//                    tlTvTitle.setVisibility(View.VISIBLE);
//                }
//            }
//        });
//        //返回iv监听
//        tlIvBack.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                removeCurrentActivity();
//            }
//        });
//        //发表评论
//        sendComment.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                showCommentDialog();
//            }
//        });
//        //作者头像
//        ivHead.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                goToActivity(My_Activity.class, new Bundle());
//            }
//        });
//        tlIvHead.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                goToActivity(My_Activity.class, new Bundle());
//            }
//        });
//        lvComment.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
//            @Override
//            public boolean onGroupClick(ExpandableListView expandableListView, View view, int groupPosition, long l) {
//                showReplyDialog(groupPosition);
//                return true;
//            }
//        });
//    }
//
//    private void initView() {
//
//        Glide.with(this)
//                .load(productBean.getHead_url())
//                .thumbnail(Glide.with(this).load(R.drawable.loading))
//                .apply(RequestOptions.bitmapTransform(new RoundedCorners(40)))
//                .into(ivHead);
//        Glide.with(this)
//                .load(productBean.getHead_url())
//                .thumbnail(Glide.with(this).load(R.drawable.loading))
//                .apply(RequestOptions.bitmapTransform(new RoundedCorners(40)))
//                .into(tlIvHead);
//        tvName.setText(productBean.getName());
//        tlTvName.setText(productBean.getName());
//        tvDate.setText(productBean.getTime());
//        tvPresentation.setText(productBean.getContent());
//        List<UrlBean> urlBeans = JSONObject.parseArray(productBean.getProducts(), UrlBean.class);
//        PhotoAdapter photoAdapter = new PhotoAdapter(urlBeans, this) {
//            @Override
//            public void onclick(String url) {
//                Util.showToast(Product_Content.this, "点击了图片，url:" + url);
//            }
//        };
//        // TODO: 2021/5/6 listview高度有问题
//        lvProduct.setAdapter(photoAdapter);
//        tvGroup.setText(productBean.getLabel().size() + "个圈子可看到");
//
//        /**
//         * 装载横向RecyclerView
//         */
//        //创建LinearLayoutManager
//        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
//        //RecyclerView设置为横向滑动
//        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
//        //设置创建LinearLayoutManager到RecyclerView中
//        rvLabel.setLayoutManager(linearLayoutManager);
//        Label_ProtoAdapter labelProtoAdapter = new Label_ProtoAdapter(productBean.getLabel(), this) {
//            @Override
//            protected void onclick(String lab_id) {
//                Util.showToast(Product_Content.this, "点击了圈子，lab_id:" + lab_id);
//            }
//        };
//        rvLabel.setAdapter(labelProtoAdapter);
//
//
//        /**
//         * 评论listview
//         */
//        //添加尾组件
////        tv_more = (TextView) LayoutInflater.from(this).inflate(R.layout.tv_comment, null);
////        lvComment.addHeaderView(tv_more);
//
//        lvComment.setGroupIndicator(null);
//        item_commentAdapter = new Item_commentAdapter(productBean.getComments(), this) {
//            @Override
//            public void headListen() {
//                goToActivity(My_Activity.class, new Bundle());
//            }
//        };
//        lvComment.setAdapter(item_commentAdapter);
//        //默认展开所有评论
//        for (int i=0; i<lvComment.getCount(); i++) {
//            lvComment.expandGroup(i);
//        };
//    }
//
//    /**
//     * 弹出评论框
//     */
//    private void showCommentDialog() {
//        // TODO: 2020/11/16 手机软键盘遮挡输入框
//        dialog = new BottomSheetDialog(this);
//        View commentView = LayoutInflater.from(this).inflate(R.layout.comment_dialog_layout, null);
//        final EditText commentText = (EditText) commentView.findViewById(R.id.dialog_comment_et);
//        final Button bt_comment = (Button) commentView.findViewById(R.id.dialog_comment_bt);
//        dialog.setContentView(commentView);
//        /**
//         * 解决bsd显示不全的情况
//         */
//        View parent = (View) commentView.getParent();
//        BottomSheetBehavior behavior = BottomSheetBehavior.from(parent);
//        commentView.measure(0, 0);
//        behavior.setPeekHeight(commentView.getMeasuredHeight());
//        bt_comment.setOnClickListener(new View.OnClickListener() {
//            @SuppressLint("CheckResult")
//            @Override
//            public void onClick(View view) {
//                String commentContent = commentText.getText().toString().trim();
//                if (!TextUtils.isEmpty(commentContent)) {
//                    //commentOnWork(commentContent);
//
//                    apiService.add_pro_comment(productBean.getId_unique(),Constant.UID,commentContent)
//                            .compose(ResponseTransformer.obtain())
//                            .subscribe(new Consumer<Product_bean.CommentsBean>() {
//                                @Override
//                                public void accept(Product_bean.CommentsBean commentsBean) throws Exception {
//                                    item_commentAdapter.addTheCommentData(commentsBean);
//                                    dialog.dismiss();
//                                }
//                            }, new ErrorConsumer() {
//                                @Override
//                                protected void error(ApiException e) {
//                                    Util.show(Product_Content.this, "评论失败:"+e.getErrorMsg());
//                                }
//                            });
////                    //获取当前时间
////                    Date date = new Date(System.currentTimeMillis());
////                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
////                    Product_bean.CommentsBean comment = new Product_bean.CommentsBean();
////                    comment.setId_unique("111");
////                    comment.setHead_url("http://114.55.249.135:8888/touxiang/a.png");
////                    comment.setName("浩南仔");
////                    comment.setContent(commentContent);
////                    comment.setTime(simpleDateFormat.format(date));
////                    item_commentAdapter.addTheCommentData(comment);
//
//                    Util.show(Product_Content.this, "评论成功");
//                } else {
//                    Util.show(Product_Content.this, "评论内容不能为空");
//                }
//            }
//        });
//
//        commentText.addTextChangedListener(new TextWatcher() {
//            @Override
//            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
//
//            }
//
//            @Override
//            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
//                if (!TextUtils.isEmpty(charSequence) && charSequence.length() > 2) {
//                    bt_comment.setBackgroundColor(Color.parseColor("#FFB568"));
//                } else {
//                    bt_comment.setBackgroundColor(Color.parseColor("#D8D8D8"));
//                }
//            }
//
//            @Override
//            public void afterTextChanged(Editable editable) {
//
//            }
//        });
//        dialog.show();
//
//    }
//
//    /**
//     * 弹出回复框
//     */
//    private void showReplyDialog(final int position) {
//        dialog = new BottomSheetDialog(this);
//        View commentView = LayoutInflater.from(this).inflate(R.layout.comment_dialog_layout, null);
//        final EditText commentText = (EditText) commentView.findViewById(R.id.dialog_comment_et);
//        final Button bt_comment = (Button) commentView.findViewById(R.id.dialog_comment_bt);
//        commentText.setHint("回复 " + productBean.getComments().get(position).getObserver_name() + " 的评论:");
//        dialog.setContentView(commentView);
//        bt_comment.setOnClickListener(new View.OnClickListener() {
//            @SuppressLint("CheckResult")
//            @Override
//            public void onClick(View view) {
//                String replyContent = commentText.getText().toString().trim();
//                if (!TextUtils.isEmpty(replyContent)) {
//                    apiService.add_pro_reply(productBean.getComments().get(position).getPc_id(),Constant.UID,productBean.getComments().get(position).getObserver_id(),replyContent)
//                            .compose(ResponseTransformer.obtain())
//                            .subscribe(new Consumer<Product_bean.CommentsBean.ReplysBean>() {
//                                @Override
//                                public void accept(Product_bean.CommentsBean.ReplysBean replysBean) throws Exception {
//                                    item_commentAdapter.addTheReplyData(replysBean, position);
//                                    lvComment.expandGroup(position);
//                                    Util.showToast(Product_Content.this, "回复成功");
//                                    dialog.dismiss();
//                                }
//                            }, new ErrorConsumer() {
//                                @Override
//                                protected void error(ApiException e) {
//                                    Util.showToast(Product_Content.this, "回复失败："+e.getErrorMsg());
//                                }
//                            });
//
////                    Product_bean.CommentsBean.ReplysBean replyListBean = new Product_bean.CommentsBean.ReplysBean();
////                    replyListBean.setReply_name("小陈");
////                    replyListBean.setContent(replyContent);
////                    item_commentAdapter.addTheReplyData(replyListBean, position);
////                    lvComment.expandGroup(position);
//                } else {
//                    Util.showToast(Product_Content.this, "回复内容不能为空");
//                }
//            }
//        });
//        commentText.addTextChangedListener(new TextWatcher() {
//            @Override
//            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
//
//            }
//
//            @Override
//            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
//                if (!TextUtils.isEmpty(charSequence) && charSequence.length() > 2) {
//                    bt_comment.setBackgroundColor(Color.parseColor("#FFB568"));
//                } else {
//                    bt_comment.setBackgroundColor(Color.parseColor("#D8D8D8"));
//                }
//            }
//
//            @Override
//            public void afterTextChanged(Editable editable) {
//
//            }
//        });
//        dialog.show();
//    }
//
//
//
//    @SuppressLint("HandlerLeak")
//    private Handler mHandler = new Handler() {
//        @Override
//        public void handleMessage(Message msg) {
//            switch (msg.what) {
//                case 1://查询失败
//                    Util.showToast(Product_Content.this, "获取文章失败："+msg.obj);
//                    LoadingDialog.getInstance(Product_Content.this).dismiss();
//                    break;
//                case 2://查询成功
//                    LoadingDialog.getInstance(Product_Content.this).dismiss();
//                    initView();//装载数据进组件
//                    break;
//
//
//            }
//        }
//    };
//    @Override
//    protected int getLayoutId() {
//        return R.layout.product_content;
//    }
//
//    @Override
//    protected void onCreate(Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//        // TODO: add setContentView(...) invocation
//        ButterKnife.bind(this);
//    }
//}
